//
//  LWNetWorkingManager.m
//  练习项目
//
//  Created by 吴丹草 on 17/1/4.
//  Copyright © 2017年 吴丹草. All rights reserved.
//

#import "LWNetWorkingManager.h"

@implementation LWNetWorkingManager

+ (instancetype)sharedManager
{
    static id instance;
    
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        
        instance = [[self alloc]init];
        
    });
    
    return instance;
}
/*
 - (nullable NSURLSessionDataTask *)GET:(NSString *)URLString
 parameters:(nullable id)parameters
 success:(nullable void (^)(NSURLSessionDataTask *task, id _Nullable responseObject))success
 failure:(nullable void (^)(NSURLSessionDataTask * _Nullable task, NSError *error))failure
 */

- (void)requestWithURLString : (NSString *)urlString withParameters : (id)parameters withMothed : (NSString *)mothed withBlock : (void(^)(id response))finished
{
    if([mothed isEqualToString:@"GET"])
    {
        [self GET:urlString parameters:parameters progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
            
            if(finished != nil)
            {
                finished(responseObject);
            }
            
        } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
           
            finished(nil);
            
        }];
    }
    
    if([mothed isEqualToString:@"POST"])
    {
        [self POST:urlString parameters:parameters progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
            
            if(finished != nil)
            {
                finished(responseObject);
            }
        } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
            
            finished(nil);
            
        }];
    }
    
}


@end
